package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.pt.MallPtUserAuto;
import com.tencreat.service.pt.IMallPtUserAutoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户自动拼团列Controller
 *
 * @author tencreat
 * @date 2021-12-15
 */
@Api(tags="用户自动拼团列api")
//@RestController
@RequestMapping("/system/auto")
public class MallPtUserAutoController extends BaseController {
   // @Autowired
    private IMallPtUserAutoService mallPtUserAutoService;

    /**
     * 查询用户自动拼团列列表
     */
    @ApiOperation(value="查询用户自动拼团列列表")
    @PreAuthorize("@ss.hasPermi('system:auto:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPtUserAuto>> list(@RequestBody  MallPtUserAuto mallPtUserAuto) {
        QueryWrapper<MallPtUserAuto> wrapper = Wrappers.query(mallPtUserAuto);
        Page<MallPtUserAuto> page =  new Page<>(mallPtUserAuto.getPageNum(), mallPtUserAuto.getPageSize());
        return HttpResult.ok(mallPtUserAutoService.page(page, wrapper));
    }

    /**
     * 导出用户自动拼团列列表
     */
    @ApiOperation(value="导出用户自动拼团列列表")
    @PreAuthorize("@ss.hasPermi('system:auto:export')")
    @Log(title = "用户自动拼团列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPtUserAuto mallPtUserAuto) {
        List<MallPtUserAuto> list = mallPtUserAutoService.selectMallPtUserAutoList(mallPtUserAuto);
        ExcelUtil<MallPtUserAuto> util = new ExcelUtil<MallPtUserAuto>(MallPtUserAuto.class);
        return util.exportExcel(list, "auto");
    }

    /**
     * 获取用户自动拼团列详细信息
     */
    @ApiOperation(value="获取用户自动拼团列详细信息")
    @PreAuthorize("@ss.hasPermi('system:auto:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPtUserAuto> getInfo(@RequestBody ReqIdParam id) {
        return HttpResult.ok(mallPtUserAutoService.selectMallPtUserAutoById(id));
    }

    /**
     * 新增用户自动拼团列
     */
    @ApiOperation(value="新增用户自动拼团列")
    @PreAuthorize("@ss.hasPermi('system:auto:add')")
    @Log(title = "用户自动拼团列", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody MallPtUserAuto mallPtUserAuto) {
        return to(mallPtUserAutoService.insertMallPtUserAuto(mallPtUserAuto));
    }

    /**
     * 修改用户自动拼团列
     */
    @ApiOperation(value="修改用户自动拼团列")
    @PreAuthorize("@ss.hasPermi('system:auto:edit')")
    @Log(title = "用户自动拼团列", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPtUserAuto mallPtUserAuto) {
        return to(mallPtUserAutoService.updateMallPtUserAuto(mallPtUserAuto));
    }

    /**
     * 删除用户自动拼团列
     */
    @ApiOperation(value="删除用户自动拼团列")
    @PreAuthorize("@ss.hasPermi('system:auto:remove')")
    @Log(title = "用户自动拼团列", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody ReqIdsParam ids) {
        return to(mallPtUserAutoService.deleteMallPtUserAutoByIds(ids));
    }
}
